//
//  DiscoverCollectionViewCellOfContentViewThird.m
//  XYFMApp
//
//  Created by 岁变 on 16/8/31.
//  Copyright © 2016年 岁变. All rights reserved.
//

#import "DiscoverCollectionViewCellOfContentViewThird.h"
#import "XYMacro.h"

@implementation DiscoverCollectionViewCellOfContentViewThird

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _backImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_backImageView];
        
        _frontImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"find_cat_cover"]];
        [self.contentView addSubview:_frontImageView];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:12];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.numberOfLines = 2;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_titleLabel];
    }
    return self;
}

- (void)setModel:(DiscoverModelFirstTypeContenModel *)model {
    [_backImageView sd_setImageWithURL:[NSURL URLWithString:model.music_img] placeholderImage:PLACEHOLDERIMAGE];
    _titleLabel.text = model.music_title;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [_backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(5);
        make.left.equalTo(self.contentView.mas_left).with.offset(5);
        make.right.equalTo(self.contentView.mas_right).with.offset(-5);
        make.height.equalTo(_backImageView.mas_width);
    }];
    
    [self.contentView layoutIfNeeded];
    _backImageView.clipsToBounds = YES;
    _backImageView.layer.cornerRadius = _backImageView.frame.size.width / 2;
    
    [_frontImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        make.height.equalTo(_frontImageView.mas_width);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_frontImageView.mas_bottom).with.offset(5);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-5);
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(0);
        
    }];
    
}
@end
